﻿@using BlazorWebAppEFCore.Grid
@inject IContactFilters Filters

<button class="btn btn-primary"
        disabled="@Filters.Loading"
        @onclick="ToggleAsync">
    @Label
</button>
&nbsp;

@code {
    // Button text based on current state.
    private string Label => Filters.ShowFirstNameFirst ?
    "Show Last Name, First Name" :
    "Show First Name, Last Name";

    // Reference to the GridWrapper.
    [CascadingParameter]
    public GridWrapper? GridWrapper { get; set; }

    // Toggle name preference.
    private Task ToggleAsync()
    {
        Filters.ShowFirstNameFirst = !Filters.ShowFirstNameFirst;

        return GridWrapper is not null ? GridWrapper.FilterChanged.InvokeAsync(this) : Task.CompletedTask;
    }
}
